| Conditions | 4 |
| Total Lines | 23 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | 5 | import { MAX_LOOPS } from './config' |
|
| 27 | |||
| 28 | /** |
||
| 29 | * Yield false for each left and true for each right. |
||
| 30 | */ |
||
| 31 | 5 | export function* pathToValue(n: number): Generator<boolean> { |
|
| 32 | 15 | let m0 = 1n, |
|
| 33 | 15 | m1 = 0n, |
|
| 34 | 15 | m2 = 0n, |
|
| 35 | 15 | m3 = 1n |
|
| 36 | 15 | const r = new Rat(1n) |
|
| 37 | 15 | for (let i = 0; i < MAX_LOOPS; i++) { |
|
| 38 | 565 | if (r.approximates(n)) break |
|
| 39 | 550 | const direction = n > +r |
|
| 40 | 550 | yield direction |
|
| 41 | 550 | if (!direction) { |
|
| 42 | 112 | m0 += m1 |
|
| 43 | 112 | m2 += m3 |
|
| 44 | } else { |
||
| 45 | 438 | m1 += m0 |
|
| 46 | 438 | m3 += m2 |
|
| 47 | } |
||
| 48 | 550 | r.n = m0 + m1 |
|
| 49 | 550 | r.d = m2 + m3 |
|
| 50 | } |
||
| 70 |